{extend name="mainadmin@layouts/base" /}
{block name="main" }

<header class="header  b-b clearfix">
   <div class="page-breadcrumbs">
          <ul class="breadcrumb">
              <li>
                  <i class="fa fa-ellipsis-v"></i>
                  <strong>编辑站内信</strong>
              </li>
          </ul>
       <a class="text-muted pull-right m-r-tm m-t-md pointer" data-toggle="back" title="返回"><i class="fa fa-reply"></i></a>
      </div>
</header>

<section class="scrollable  wrapper">
<form class="form-horizontal form-validate" method="post" action="{:url('info')}" style="padding:0;">
      <section class="panel panel-default">
          <header class="panel-heading bg-light">
              基本信息
          </header>
          <div class="panel-body">

              <div class="form-group">
                  <label class="control-label">消息标题：</label>
                  <div class="controls" >
                      <input type="text" class="input-xlarge" data-rule-maxlength="40" data-rule-required="true" data-msg-required="文章标题不能为空" name="title" value="{$row.title}" >
                  </div>
              </div>
              <div class="form-group">
                  <label class="control-label">消息内容：</label>
                  <div class="col-sm-8" >
                      <textarea name="content" class="input-xxlarge">{$row.content}</textarea>
                  </div>
              </div>

              <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="control-label">绑定关联：</label>
                  <div class="controls" >
                      <input name="article_title" id="article_title"  class="input-xlarge" style="width:50%;" type="text" readonly value="{$row.article_title}">
                      <input name="article_id" id="article_id" type="hidden" value="{$row.article_id}">
                      <a href="javascript:;" data-remote="{:url('publics/sys_admin.links/index',['linksfun'=>'assigBack','linkstype'=>'article'])}"  data-toggle="ajaxModal" class="type_bding_btn btn btn-sm btn-default " id="links_btn" >绑定文章</a>
                  </div>
              </div>

              <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="control-label">发送时间：</label>
                  <div class="col-sm-2">
                      <div class="input-group">
                          <input type="text" class="input-max" name="send_time" id="send_time" value="{$row.send_time|dateTpl='',true}" readonly="readonly" data-before="#send_end_date" data-toggle="datetimepicker" data-position="top-right"/>
                          <span  class="input-group-addon"><i class="fa fa-calendar"></i></span>
                      </div>
                  </div>
              </div>
              <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="control-label">显示过期时间：</label>
                  <div class="col-sm-2">
                      <div class="input-group">
                          <input name="show_end_time" type="text" class="input-max" id="show_end_time" value="{$row.show_end_time|dateTpl='',true}" readonly="readonly" data-after="#send_start_date" data-toggle="datetimepicker" data-position="top-right"/>
                          <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                      </div>
                  </div>
                  <label>超出此时间后，站内信将会从用户站内信列表消失。该时间最大可设置为发送结束日期三个月后</label>
              </div>



              <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="control-label">通知发送类型：</label>
                  <div class="col-sm-10">
                      {if condition="$row.message_id > 0"}
                      <label>{$messageType[$row['type']]}</label>
                      <input type="hidden" name="type" value="{$row['type']}">
                      {else/}
                      {volist name="messageType" id="st" }
                      <label>
                          <input name="type" value="{$key}" type="radio" class="js_radio_undertake" {$row['type']|tplckval=$key,'checked'} data-class="type_select_{$key}">
                          {$st}
                      </label>
                      {/volist}
                      {/if}
                  </div>
              </div>

              <div class="line line-dashed line-lg pull-in"></div>
              <div class="form-group">
                  <label class="control-label">通知状态：</label>
                  <div class="col-sm-10">
                      <label>
                          <input name="status" value="1" class="js_inventory" type="radio" {$row['status']|tplckval='=1','checked',true}>
                          正常
                      </label>
                      <label>
                          <input name="status" value="0" class="js_inventory" type="radio" {$row['status']|tplckval='=0','checked'}>
                          失效
                      </label>
                  </div>
              </div>
              <div class="radio_undertake_type type_select_channel {$row['type']=='channel'?'':'hide'}">
                  <div class="line line-dashed line-lg pull-in"></div>
                  <div class="form-group">
                      <label class="control-label">指定代理层级：</label>
                      <div class="col-sm-10">
                          <select class="input-xlarge" name="proxy_id" {$row['message_id']>0?'disabled':''}>
                              <option value="0" {$row['type_ext_id']==0?'selected':''} >全部代理</option>
                              {volist name="proxyList" id="arr" }
                              <option value="{$arr.proxy_id}" {$arr['proxy_id']==$row['type_ext_id']?'selected':''} >{$arr.proxy_name}</option>
                              {/volist}
                          </select>
                      </div>
                  </div>
              </div>
              <div class="radio_undertake_type type_select_distribution {$row['type']=='distribution'?'':'hide'}">
                  <div class="line line-dashed line-lg pull-in"></div>
                  <div class="form-group">
                      <label class="control-label">指定分销身份：</label>
                      <div class="col-sm-10">
                          <select class="input-xlarge" name="role_id" {$row['message_id']>0?'disabled':''}>
                              <option value="0" {$row['type_ext_id']==0?'selected':''} >粉丝</option>
                              {volist name="roleList" id="arr" }
                              <option value="{$arr.role_id}" {$arr['role_id']==$row['type_ext_id']?'selected':''} >{$arr.role_name}</option>
                              {/volist}
                          </select>
                      </div>
                  </div>
               </div>

              <div class="radio_undertake_type type_select_byuser {$row['type']=='byuser'?'':'hide'}">
                  <div class="line line-dashed line-lg pull-in"></div>
                  <div class="form-group" id="goodsListTable">
                      <label class="control-label">会员列表：</label>
                      <div class="col-sm-3">
                          <table class="table table-bordered table-striped " style="width:800px;">
                              <thead>
                              <tr>
                                  <th width="100">会员ID</th>
                                  <th>会员昵称</th>
                                  <th>手机号码</th>
                                  <th width="170">操作
                                      {if condition="$row['message_id']<1"}
                                      <a href="javascript:selectUsers();"  title="选择会员" class="btn btn-default"><i class="fa fa-plus m-r-xs">选择会员</i></a>
                                      {/if}
                                  </th>
                              </tr>
                              </thead>
                              <tbody id="user_box">
                              {foreach name="$userList" item="vo"}
                                <tr>
                                    <td>{$vo.user_id}</td>
                                    <td>{$vo.mobile}</td>
                                    <td>{$vo.nick_name}</td>
                                    <td> <a href="javascript:;" class="btn" >已发送</a> </td>
                                </tr>
                              {/foreach}
                              </tbody>
                          </table>
                      </div>
                  </div>
              </div>
              <input name="message_id" type="hidden" value="{$row.message_id}">
              <div class="form-group">
                  <div class="col-sm-4 col-sm-offset-2">
                      <button type="submit" class="btn btn-primary" data-loading-text="保存中...">保存</button>
                      <button type="button" class="btn btn-default" data-toggle="back">取消</button>
                  </div>
              </div>
           </div>
      </section>

	<input name="id" type="hidden" value="{$row.id|intval}">
</form>
</section>
<script>

    function assigBack(type,type_id,id,title,url){
        $("#article_id").val(id);
        $("#article_title").val(title);
        $(".modal-dialog .close").trigger("click");
    }
    //删除会员
    function delLinkUser(select_type, key_val) {
        $('#' + select_type + '_tr_' + key_val).remove();
    }
    //选择会员
    function selectUsers(use_type)
    {
        var usersArr=[];
        $('#user_box').find('input').each(function () {
            usersArr.push($(this).val());
        })
        var url = "{:url('member/sys_admin.users/searchBox')}"+'?usersArr='+usersArr+'&'+Math.random();
        layer.open({
            type: 2,
            title: '选择会员',
            shadeClose: true,
            shade: 0.3,
            area: ['70%', '80%'],
            content: url,
        });
    }
    function call_back(Arr)
    {
        layer.closeAll('iframe');
        $.each(Arr, function (n, value) {
            console.log(Arr)
            var html='';
            html+='<tr id="user_tr_'+value.user_id+'">';
            html+='<td><input name="user_id[]" type="hidden" value="'+value.user_id+'" />'+value.user_id+'</td>';
            html+='<td>'+value.mobile+'</td>';
            html+='<td>'+value.nick_name+'</td>';
            html+='<td><a href="javascript:;" title="删除" class="fa btn fa-remove m-xs" onclick="delLinkUser(\'user\','+value.user_id+')" >删除</a></td>';
            html+='</tr>';
            $('#user_box').append(html);
        });
    }

</script>


{/block}
